/************************************************
*
*   filename:   Engine.h
*   date:       11/12/09
*
*   Created by
*       Kassandra Kaplan
*
*   purpose:
*       Game engine class methods
*
*   Revisions:
*       - 11/12/09
*            Ceated header
*
*
*   copyright 2009 by
*       Cy Cook
*       Kassandra Kaplan
*       Blaise Millegan
*       Jason Stafford
*
************************************************/
#include <iostream>
#include "Engine.h"

using namespace std;
    // creates a place to draw the screen
void engine::draw()
{


}//void engine::draw()

Uint8 engine::key_input()
{
       //if there's an event to handle
    if( SDL_PollEvent( &event ) == true)
    {
        if (event.type == SDL_QUIT)
        {
            return SDL_QUIT;
        }
        else
        {
        return event.key.keysym.sym;
        }
    }
    else
    {
        return 0;
    }

}
    // creates a place to update all game logic
bool engine::update()
{
    bool stop_game = false;    //While the user hasn't quit

    if(this->key_input() == SDL_QUIT)
    {
        stop_game= true;
    }

    if(this->key_input() == SDLK_ESCAPE)
    {
        stop_game= true;
    }

    if(stop_game == false)
    {
    stop_game = my_scene->update(main_game);
    }

    return stop_game;
}//bool engine::update()

// Start up of the engine
bool engine::init()
{
    // insert the initialization code

    //Initialize all SDL subsystems

    if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
    {
        return false;
    }

    //Set up the screen
    screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );

    //If there was an error in setting up the screen
    if( screen == NULL )
    {
        return false;
    }

    //Set the window caption
    SDL_WM_SetCaption( "RPG BATTLE - Final project fall '09", NULL );

    //If everything initialized fine
    return true;
}

// closing down of the engine
void engine::close()
{
  // insert the closing code

    //Quit SDL
    SDL_Quit();
}

engine::engine()
{
    this->redraw_mode = dynamic_fps;
    this->redraw_rate = 60;
    screen = NULL;
    my_scene = new scene();
    main_game = new game_info();
}//engine::engine()

engine::~engine()
{
    delete my_scene;
    delete main_game;
}//engine::engine()

    // determines the logic for screen redraw
bool engine::redraw()
{

    bool will_redraw = true;
    // determines the mode the engine is using
    // allows for the logic
    switch(redraw_mode)
    {
        case dynamic_fps:
        will_redraw = true;
        break;
        case fixed_fps:
        // code for creating a fixed fps system if
        // implementation is needed
        break;
        default:
        will_redraw = true;
    }
    return will_redraw;
}//bool engine::redraw()
